//Complex.hpp
#ifndef _COMPLEX_HPP_
#define _COMPLEX_HPP_
#include <iostream>
#include <cmath>
using namespace std;
class Complex {
	private:
        double real;    //实部
	    double image;   //虚部
	
	public:
        Complex() { //无参构造
        }

	    Complex(double real, double image) {//带参构造
            this->real = real;
            this->image = image;
	    }

        Complex(const Complex& complex) {//拷贝构造
            this->real = complex.real;
            this->image = complex.image;
	    }

        void add(const Complex& complex) {
            this->real += complex.real;
            this->image += complex.image;
        }

        void sub(const Complex& complex) {
            this->real -= complex.real;
            this->image -= complex.image;
        }

        void mult(const Complex& complex) {
            double temp = this->real;
            this->real = this->real * complex.real - this->image * complex.image;
            this->image = temp * complex.image + this->image * complex.real;
        }

        void div(const Complex& complex) {
            if ((complex.real == 0) && (complex.image == 0)) {
                cout << "除数不能为0" << endl;
                return;
            }
            double tempReal;
            double tempImage;
            tempReal = this->real * complex.real + this->image * complex.image;
            tempImage = this->image * complex.real - this->real * complex.image;
            tempReal = tempReal / (pow(complex.real, 2) + pow(complex.image, 2));
            tempImage = tempImage / (pow(complex.real, 2) + pow(complex.image, 2));
            this->setReal(tempReal);
            this->setImage(tempImage);
        }

        void display() {
            cout << "(";
            cout << this->real;
            cout << ((this->image) > 0 ? "+" : "-");
            //cout << "+";
            cout << abs(this->image) << "i";
            cout << ")";
        }

        double getReal() {
            return real;
        }
	
        void setReal(double real) {
            this->real = real;
        }

        double getImage() {
            return image;
        }

        void setImage(double image) {
            this->image = image;
        }
};
#endif